class BootStrap {

     def init = { servletContext ->
     	def world = new World(name:'world').save()
     	
     	def ground = new CubeType(world:world, name:'ground', center:SLGState.GASEOUS, floor:SLGState.SOLID).save()
     	def water = new CubeType(world:world, name:'water', center:SLGState.LIQUID).save()
     	def air = new CubeType(world:world, name:'air', center:SLGState.GASEOUS).save()
     
     	def place = new Place(world:world, name:'place').save()
     	
     	for (z in (0..<1)) {
	     	for (y in (0..<10)) {
		     	for (x in (0..<20)) {
		     		def cubeType = ground
		     		if (z > 0) cubeType = air
		     		if (z == 0 && x > 4 && x < 7) cubeType = water
		     		def cube = new Cube(place:place, x:x, y:y, z:z, type:cubeType).save()
		     		place.addToCubes(cube)
		     	}
	     	}
     	}
     	place.save()
     	
     	def money = new Resource(world:world, name:'money').save()
     	
     	def human = new Race(world:world, name:'Human').save()
     	
     	def soldier = new UnitType(race:human, name:'Soldier', life:1, move:5).save()
     	def tank = new UnitType(race:human, name:'Tank', life:5, move:2).save()
     	
     	def user1 = new User(name:'user').save()
     	def user2 = new User(name:'computer').save()
     	
     	def teamA = new Team(race:human, user:user1, name:'team A', color:'0000FF').save()
     	def teamB = new Team(race:human, user:user2, name:'team B', color:'FF0000').save()
     	
     	def soldierA1 = new Unit(team:teamA, type:soldier).save()
     	def soldierA2 = new Unit(team:teamA, type:soldier).save()
     	def soldierA3 = new Unit(team:teamA, type:soldier).save()

     	def soldierB1 = new Unit(team:teamB, type:soldier).save()
     	def soldierB2 = new Unit(team:teamB, type:soldier).save()
     	def soldierB3 = new Unit(team:teamB, type:soldier).save()
     	
     	Cube.findWhere(place:place, x:2, y:1, z:0).unit = soldierA1
     	Cube.findWhere(place:place, x:1, y:4, z:0).unit = soldierA2
     	Cube.findWhere(place:place, x:3, y:6, z:0).unit = soldierA3
     	Cube.findWhere(place:place, x:8, y:2, z:0).unit = soldierB1
     	Cube.findWhere(place:place, x:7, y:3, z:0).unit = soldierB2
     	Cube.findWhere(place:place, x:9, y:7, z:0).unit = soldierB3
     	
     	def game = new Game(world:world, place:place).save()
     	game.addToPlayers(user1)
     	game.addToPlayers(user2)
     	game.save()
     	
     }
     
     def destroy = {
     }
} 